<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<%@ page pageEncoding="UTF-8" %>
<%@ page import="jp.co.technotree.apl.api.common.Message,jp.co.technotree.common.ApplicationManager" %>
<%@ include file="../common/common.jsp"%>
<%@ page import="jp.co.technotree.apl.cmd.master.Mst3000Bean;" %>
<jsp:useBean id="formBean" class="jp.co.technotree.apl.cmd.master.Mst3000Bean" scope="request" />

<%

Mst3000Bean.carendarRecord[] recordList = formBean.getRecordList();

%>


<html>
	<head>
		<title>予備品管理システム - 稼働日情報メンテナンス画面</title>
		<link rel="SHORTCUT ICON" href="../common/img/default/sys_icon.ico">

		<link rel='stylesheet' type='text/css' href='../../common/css/common/base.css' >
		<link rel='stylesheet' type='text/css' href='../../common/css/common/common.css'>
		<link rel='stylesheet' type='text/css' href='../../common/css/master/mst3000.css'>
		<link rel='stylesheet' type='text/css' href='../../common/css/master/mst3000_calendar.css'>
		<!--ポップアップ用-->
		<link rel='stylesheet' type='text/css' href='../../common/css/popUpPc.css' >
		
		<script type='text/javascript' src='../../common/js/popUpPc.js'></script>
		<script language="javascript" src="../../common/js/base.js"></script>
		<script language="javascript" src="../../common/js/menu/topmenu.js"></script>
		<script language="javascript" src="../../common/js/master/mst3000_calendar.js"></script>


		<!-- システムログ -->
		<script src="../../common/js/systemlog.js"></script>

<style type='text/css'>
	.LinkItem {
		cursor: pointer;
	}
</style>

<script language="javascript">
var yyyymm="";

function onInit(){

	//発注完了後、メッセーを出してメイン画面に遷移
	var stateFlg = "<%=formBean.getStateFlg()%>";

	var afterFunc="nextPageJump('mst2000');"
	if(stateFlg == "00"){
		
	    document.getElementById("yymmUpdate").value = "<%=formBean.getYymmUpdate()%>";
		
		//INF00040=$1を正常に変更しました。
		alert_Info2("<%=Message.getMessage("INF00040").replace("$1", "稼働日情報")%>",afterFunc);
		
	}
	
	//---------------------------------------------
	var updateYYmm = "<%=formBean.getYymmUpdate()%>";
	

	//====================================
	var date = new Array();///
	date[0] =  updateYYmm.substring(0,4);  //年
	date[1] =  updateYYmm.substring(4,6);   //月
	
	//yyyymm = date[0] +"-"+ date[1];
	yyyymm = updateYYmm;

	var divList = new Array();
	divList = setDateCalendar();
	
	calendar(date, divList);
	//====================================

}


//変更ボタンを押下
function updateBtnExe(){
	mainForm = document.getElementById("F1");
	
	var checkDivList ="";
	
	var divList = new Array();
	divList = setDateCalendar();
	
	//稼働日リストの取得
    for(var i=1; i<=divList.length;i++){
    	
    	var chekDiv = document.getElementById("hdInput"+i).value;
    	
    	if(chekDiv=="1"){
    		checkDivList += ","+i;
    	}
    }
	
	//最初のコンマを消去
    checkDivList  =  checkDivList.replace(",","")
	
    document.getElementById("checkDivList").value = checkDivList;
    document.getElementById("stateFlg").value = "1";
    document.getElementById("yymmUpdate").value = yyyymm;
    
    
	
	//INF01070=$1を変更します。よろしいですか?
	if ("undefind"!=confirm_Custom("<%=Message.getMessage("INF01070").replace("$1", "稼働日情報")%>")){
		return ;
	}
	
    mainForm.submit();
}



//変更ボタンを押下
function updateBtn(){
	
    document.getElementById("yymmUpdate").value = yyyymm;
	
	//更新日を比較
	 updateDtCheck(yyyymm);
	
	
}




//ページ遷移
function nextPageJump(nextPage){

	mainForm = document.getElementById("F1");
	document.getElementById("nextPage").value = nextPage;
	
	mainForm.submit();
}


//戻るボタン押下
function screen_back(){
	
	mainForm = document.getElementById("F1");
	document.getElementById("nextPage").value = "mst2000";
	document.getElementById("yymmUpdate").value = "<%=formBean.getYymmUpdate()%>";
	
	document.getElementById("stateFlg").value = "";
	
	//INF01051=$1を取消します。よろしいですか？
	if ("undefind"!=confirm_Custom("<%=Message.getMessage("INF01051").replace("$1", "稼働日変更")%>")){
		return ;
	}
	
}





//ＤＢから取得された値をカレンダー用の値にセット
function setDateCalendar(){
	
	var arrDiv = new Array();
	
	<%
	for(int i=0; i<recordList.length;i++){
	%>
		arrDiv[<%=i%>] = <%=recordList[i].div%>
	
  <%}%>
	
	return arrDiv;
}




//============================================================================
//ajax処理
//============================================================================
function JSONConvert(node){
	var type = node.nodeType;
	if ( isTextNode(node) ){
		var text = getTextValue(node);
		return text;
	}
	if ( type==1 ){
		var json = {};
		var nodeName = node.nodeName;
		var childs = node.childNodes;

		for (var i = 0; i<childs.length; i++){
			var child = childs[i];
			var obj = json[child.nodeName];

			if ( child.nodeType == 1 ){
				if ( obj ){
					var array = null;
					if ( !isArray(obj) ){
						array=[];
						array[array.length]=obj;
					}else{
						array=json[child.nodeName];
					}
					array[array.length]=JSONConvert(child);
					json[child.nodeName]=array;
				}else{
					json[child.nodeName]=JSONConvert(child);
				}
			}
		}
		return json;
	}
}

function isTextNode(node){
	if ( node.hasChildNodes() ){
		var childs = node.childNodes;
		for (var i = 0; i<childs.length; i++){
			var child = childs[i];
			if ( child.nodeType != 3 ) return false;
		}
	}
	return true;
}

function getTextValue(node){
	if ( node.hasChildNodes() ){
		var childs = node.childNodes;
		var child = childs[0];
		if ( child.nodeType == 3 ){
			return child.nodeValue;
		}
	}
	return null;
}
//------------------------------------------------------------------------------


//*************************************************
//AJAX 部分(稼働日の更新日を比較)
//*************************************************
function updateDtCheck(yyyymmdd){
	
	
	xmlHttp = new XMLHttpRequest();
	xmlHttp.onreadystatechange = checkStatus2;
	xmlHttp.open("GET","../mst3001/mst3001?findUpdate="+yyyymmdd,true);
	xmlHttp.send(null);

}

function checkStatus2(){

	if (xmlHttp.readyState == 4 && xmlHttp.status == 200){
		var xml = xmlHttp.responseXML;
		var rootNodes = xml.getElementsByTagName("list");
		var rootNode = rootNodes[0];
		var json = JSONConvert(rootNode);
		if (json==null) {
		}else {
			var oldUpdateDt = json.updatedt; 	 								//DB日付
			var updateDt    = document.getElementById("updateDt").value;        //  日付
			
			if(oldUpdateDt!=updateDt){

				afterFunc ="nextPageJump('mst2000_updated');"
				//WRN01550=稼働日情報が既に変更されています。稼働日の登録を再度やり直して下さい。
				alert_Custom2("<%=Message.getMessage("WRN01550")%>",afterFunc);
					
				return;
			}else{
				
				updateBtnExe();
			}

		}
	}
}
//=-----------------------------------------------------------------




//パップアップ解除
function back(){
	document.getElementById("opAlertBtn").style.display = "none";
	document.getElementById("opAlert").style.display = "none";
	document.getElementById("opAlertButton").style.display = "none";
	document.getElementById("opAlertTop").style.display = "none";
	document.getElementById("allbackgr").style.display = "none";
}



</script>

</head>

	<body onLoad="onInit()" style="margin: 0px 4px 0px 0px;">
	    <form name="main" id="F1" action="./mst3000" method="post" class="frmMain" enctype="multipart/form-data" onsubmit="return false;">
		
			<table class="tblMain" width="100%" cellspacing="0" cellpadding="0" border="0">
				<tr>
					<td valign="top">
						<table class='main-width-tb'  cellspacing='0' cellpadding='0' border='0'><tr><td></td></tr></table>
						<table class='main-height-tb' cellspacing='0' cellpadding='0' border='0'><tr><td></td></tr></table>

						<!-- Header Menu START -->
						<div class="header-title">予備品管理システム(<%=formBean.kojou%>)</div>
						<!-- Header Menu END -->

						<!-- ***** [FORM] MAIN-FORM ***** -->
						<div id="lc-out" style="z-index: 0;">
							<div id="lc-in" style="z-index: 0">

								<div  style="margin: 20px ; width: 98%;">
									<div class="subtitle">稼働日情報メンテナンス画面(変更)</div>
									<table  border="0" style="width: 98%;">
										<tr>
											<td >
												<table  border="0" style="width: 98%;" class="txtCenter">
													<tr height="20px" ><td></td></tr>
													<tr>
														<td>
															<div id="calendar"></div>
														</td>
													</tr>
												</table>

												<table height="30px" width="98%" ><tr><td></td></tr></table>
												<table height="30px" width="98%" class="borderTop"><tr><td></td></tr></table>

												<table border="0" width=98%>
												<!-- 	<tr>
														<td>
															メンテ担当者
														</td>
														<td>
															<select name="example" class="selectStyle" style="width:160px;">
															<option value="サンプル1">KF111</option>
															<option value="サンプル2">サンプル2</option>
															<option value="サンプル3">サンプル3</option>
															</select>
															 &nbsp;&nbsp;&nbsp;&nbsp;
															<select name="example" class="selectStyle" style="width:160px;">
															<option value="サンプル1">加藤</option>
															<option value="サンプル2">サンプル2</option>
															<option value="サンプル3">サンプル3</option>
															</select>
														</td>

													</tr> -->
													<tr>
														<td class="txtright" colspan="2">
															<input type="image" src="../../common/img/pc/btn_update_off.png" onclick="updateBtn()" alt="変更">
															&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
															<input type="image" src="../../common/img/pc/btn_back_off.png" onclick="screen_back()" alt="戻る">
														</td>
													</tr>
												</table>
												<table height="10px" width="98%" ><tr><td></td></tr></table>
											</td>
										</tr>
									</table>
								</div>
							</div><!-- lc-in End -->


							<!-- ログ Start -->
							<!-- ログ End -->

						</div><!-- lc-out  -->
					</td>
				</tr>
			</table>
		
			<!--警告 ポップアップ---------------------------------------------------------------------------- -->
			<div id="allbackgr" class="allbackgr" style="display:none;"></div>
			<div class="opAlertBtn" id = "opAlertBtn" style="display:none;" ></div>
			<div class="opAlertButton" id = "opAlertButton" style="display:none;" ></div>
			<div class="opAlertTop" id = "opAlertTop" style="display:none; font-size:22px;">　予備品管理システム　</div>
			<div class="opAlert" id = "opAlert" style="display:none;"></div>
			<!-- -------------------------------------------------------------------------------------------- -->
			

			<input type="hidden" name="cmd" value="cmd01">
			<input type="hidden" name="submitType" id="submitType" value="">
			<input type="hidden" name="deleteSheet" id="deleteSheet" value="">
			<input type="hidden" name="deleteSheetName" id="deleteSheetName" value="">
			<input type="hidden" id="nextPage" name="nextPage" value="">
				
			<input type="hidden" name="yymmUpdate" id="yymmUpdate" value="<%=formBean.getYymmUpdate().substring(0,4)%>">
			<input type="hidden" name="checkDivList" id="checkDivList" value="">
			<input type="hidden" name="stateFlg" id="stateFlg" value="">
			<input type="hidden" name="findYear" id="findYear" value="">
			<input type="hidden" name="updateDt" id="updateDt" value="<%=formBean.getUpdateDt()%>">
		</form>
	</body>
</html>
